<!-- 产品价格信息 -->
<template>
  <div class="clas_All">
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-form :model="AllotList" size="small" :inline="true">
            <el-form-item prop="">
              <el-input
                v-model="AllotList.foodName"
                placeholder="菜品名称"
                clearable
              />
            </el-form-item>
            <el-form-item prop="">
              <el-input
                v-model="AllotList.foodCode"
                placeholder="菜品编码"
                clearable
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="getfoodAndPrice"
                >查询</el-button
              >
              <el-button
                type="primary"
                size="mini"
                v-hasPermi="['bom:food:update']"
                @click="dialogVisible = true"
                >更新数据</el-button
              >
              <el-button
                type="primary"
                v-hasPermi="['bom:food:updateAll']"
                size="mini"
                @click="UpdateAllFoode"
                >更新全部数据</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col>
        <eltab
          :columns="columns"
          :showProduct="true"
          @row-click="Onclick"
          :tableData="tableData"
        ></eltab>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="AllotList.pageNum"
          :limit.sync="AllotList.pageSize"
          @pagination="getfoodAndPrice"
        />
      </el-col>
    </el-row>
    <el-dialog title="更新数据" :visible.sync="dialogVisible" width="30%">
      <div class="top_Noe">
        <el-form :model="queryparams" size="small" :inline="true">
          <el-form-item prop="foodCode">
            <el-input
              v-model="queryparams.foodCode"
              placeholder="菜品编码"
              clearable
            />
          </el-form-item>
          <el-button type="primary" size="mini" @click="UpdateFoode">
            更新
          </el-button>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import eltab from "@/components/ElTable/index";
import {
  getfoodAndPrice,
  updateFood,
  updateAllFood,
  setIs0pen,
} from "@/api/system/information";
export default {
  components: { eltab },
  data() {
    return {
      total: 0,
      queryparams: {
        foodCode: "",
      },
      AllotList: {
        pageNum: 1,
        pageSize: 10,
        foodName: "",
        foodCode: "",
      },
      dialogVisible: false,
      columns: [
        { label: "菜品编码", prop: "foodCode" },
        { label: "菜品名称", prop: "foodName" },
        { label: "菜品单位", prop: "unit" },
        { label: "菜品分类", prop: "foodCategoryName" },
        { label: "菜品单价", prop: "price" },
      ],
      tableData: [],
    };
  },
  methods: {
    getfoodAndPrice() {
      // console.log(this.AllotList);
      getfoodAndPrice(this.AllotList).then((res) => {
        res.rows.forEach((element) => {
          if (element.isOpen == "true") {
            element.isOpen = true;
          } else if (element.isOpen == "false") {
            element.isOpen = false;
          } else {
            element.isOpen = true;
          }
        });
        this.tableData = res.rows;
        this.total = res.total;
        // console.log(res);
      });
    },
    // 单个数据更新
    UpdateFoode() {
      if (this.queryparams.foodCode != "") {
        updateFood(this.queryparams).then((res) => {});
      }
    },
    // 全部数据更新
    UpdateAllFoode() {
      updateAllFood().then((res) => {});
    },
    Onclick(v) {
      // console.log(v);
      setIs0pen(v.id).then((res) => {
        if (res.code == 200) {
          this.getfoodAndPrice();
        }
      });
    },
  },
  created() {
    this.getfoodAndPrice();
  },
};
</script>

<style lang="scss" scoped>
.top_Noe {
  width: 320px;
  margin: 0 auto;
}
.clas_All {
  margin: 20px;
}
// .top_neo{}
</style>
